#include "../base.h"
#include "../include/Button.h"
#include <stdio.h>

#define LOG_TAG "TextView"

extern jobject getActivity();

static jclass getClass(JNIEnv* env,const char * className)
{
	return (*env)->FindClass(env,className);
}

static jclass getButtonClass(JNIEnv* env)
{
	return getClass(env,"android/widget/Button");
}


//创建一个按钮
Button newButton()
{
	JNIEnv* env = Android_JNI_GetEnv();
	jclass clazz = getButtonClass(env);
	static jmethodID methoID = NULL;
	if(methoID==NULL)
		methoID = (*env)->GetMethodID( env,clazz,"<init>","(Landroid/content/Context;)V" );
	jobject obj = (*env)->NewObject(env,clazz,methoID,getActivity());
	Button view = (*env)->NewGlobalRef(env,obj);
	(*env)->DeleteLocalRef(env,obj);
	(*env)->DeleteLocalRef(env,clazz);
	return view;
}

//删除一个Button
void deleteButton(Button thiz)
{
	if(thiz==NULL)
	{
		LOGE("deleteButton thiz==NULL");
		return ;
	}
	JNIEnv* env = Android_JNI_GetEnv();
	(*env)->DeleteGlobalRef(env,thiz);
}

